import { store } from "@/store";

import { defineStore } from "pinia";

const useAppStore = defineStore("app", () => {
  // 侧边栏的开关
  const isOpen_sider = useStorage("isOpen_sider", true);
  // 文件上传列表的窗口开关
  // const isOpen_uploadList = useStorage("isOpen_uploadList", false);
  const isOpen_uploadList = ref(false);
  // 上传的文件
  const files_e = ref(null);
  // 全局drag上传页面显示
  const ElUpload_show = ref(false);
  // 全局tableList刷新标识
  const tableList_isRefresh = ref(0);
  // 搜索内容
  const search_inputText = ref("");
  // 侧边栏的开关
  function toggle_isOpen_sider(bool: boolean) {
    isOpen_sider.value = bool;
  }
  // 文件上传列表的窗口开关
  function toggle_isOpen_uploadList(bool: boolean) {
    isOpen_uploadList.value = bool;
  }

  // 文件上传列表的窗口开关
  function update_files(e: any) {
    files_e.value = e;
  }
  // 全局drag上传页面显示
  function toggle_ElUpload_show(bool: boolean) {
    ElUpload_show.value = bool;
  }
  // 全局drag上传页面显示
  function edit_tableList_isRefresh(num?: number) {
    tableList_isRefresh.value++;
  }
  // 修改搜索内容
  function edit_search_inputText(str: string) {
    search_inputText.value = str;
  }

  return {
    isOpen_sider,
    isOpen_uploadList,
    files_e,
    ElUpload_show,
    tableList_isRefresh,
    search_inputText,
    toggle_isOpen_sider,
    toggle_isOpen_uploadList,
    update_files,
    toggle_ElUpload_show,
    edit_tableList_isRefresh,
    edit_search_inputText,
  };
});

export function useAppStoreHook() {
  return useAppStore(store);
}
